/*
 * @Author: xiaoyan
 * @Date: 2021-09-23 10:44:44
 * @LastEditors: xiaoyan
 * @LastEditTime: 2021-09-23 11:01:49
 * @Description: aes加密
 * @FilePath: \vue3-ts-demo\src\utils\ase.ts
 */
import { AES, mode, pad, enc } from 'crypto-ts'
import Keys from '@/constant/key'

export default class VAES {
  static key = enc.Utf8.parse(Keys.aseKey)

  static iv = enc.Utf8.parse(Keys.aseIv)

  static encrypt(text: string | null): string | null {
    return AES.encrypt(text ?? '', VAES.key, {iv: VAES.iv, mode: mode.CBC, padding: pad.PKCS7 }).toString()
  }

  static decrypt(text: string | null): string | null {
    return AES.decrypt(text ?? '', VAES.key, {iv: VAES.iv, mode: mode.CBC, padding: pad.PKCS7 }).toString(enc.Utf8)
  }
}